package com.java.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author jingjintao
 * @date 2021/6/18 - 22:41
 **/
public class Response1 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("到response1 一游");
        req.setAttribute("key1","val1");
        //方式1.
        //1.1设置响应状态码为302  表示重定向（已搬迁）
//        resp.setStatus(302);
//        //1.2设置响应头 说明新的地址在哪里
//        resp.setHeader("Location","http://localhost:8080/servlet02/response2");
//        resp.setHeader("Location","http://localhost:8080/servlet02/WEB-INF/form.html");
//        resp.setHeader("Location","http://www.baidu.com");
        //方式二
        resp.sendRedirect("http://localhost:8080/servlet02/response2");
    }
}
